const txhRecallModel = require('../modules/txhRecall')

class articleController {
  /**
     * 创建内容
     * @param ctx
     * @returns {Promise.<void>}
     */
  static async addNew(ctx) {
    const data = ctx.request.body
    console.log('data', data)
    txhRecallModel.createData(data)
    ctx.response.status = 200;
    ctx.body = {
      result: '000000',
      msg: 'ok',
    }
  }

  // 删除内容
  static async deleteContent(ctx) {
    const data = ctx.request.body
    if (data.id) {
      const ret = await txhRecallModel.deleteContent(data.id)
      console.log('ret', ret)
      ctx.response.status = 200;
      ctx.body = {
        result: '000000',
        msg: 'ok',
        data: ret,
      }
    } else {
      ctx.response.status = 200;
      ctx.body = {
        result: '000000',
        msg: '缺少id',
      }
    }
  }

  // 查找内容
  static async findContentById(ctx) {
    const data = ctx.request.body
    if (data.id) {
      const ret = await txhRecallModel.findContentById(data.id)
      ctx.response.status = 200;
      ctx.body = {
        result: '000000',
        msg: 'ok',
        data: ret,
      }
    } else {
      ctx.response.status = 200;
      ctx.body = {
        result: '000000',
        msg: '缺少id',
      }
    }
  }

  // 查找内容
  static async findContentByContent(ctx) {
    const data = ctx.request.body
    if (data.content) {
      const ret = await txhRecallModel.findContentByContent(data.content)
      ctx.response.status = 200;
      ctx.body = {
        result: '000000',
        msg: 'ok',
        data: ret,
      }
    } else {
      ctx.response.status = 200;
      ctx.body = {
        result: '000000',
        msg: '缺少id',
      }
    }
  }

  // 查找内容
  static async updateContentById(ctx) {
    const data = ctx.request.body
    if (data.id && data.content) {
      const ret = await txhRecallModel.updateContentById(data.id, data.content)
      ctx.response.status = 200;
      ctx.body = {
        result: '000000',
        msg: 'ok',
        data: ret,
      }
    } else {
      ctx.response.status = 200;
      ctx.body = {
        result: '000000',
        msg: '缺少id或者content',
      }
    }
  }

  // 生成视频
  static async createVideo(ctx) {
    const data = ctx.request.body
    if (data.id) {
      const ret = await txhRecallModel.findContentById(data.id)
      console.log('rettttt', ret[0].dataValues.content)
      ctx.response.status = 200;
      ctx.body = {
        result: '000000',
        msg: 'ok',
        data: ret,
      }
    } else {
      ctx.response.status = 200;
      ctx.body = {
        result: '000000',
        msg: '缺少id或者content',
      }
    }
  }
}

module.exports = articleController
